{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "——————\n",
    "\n",
    "*日期：2023年3月13日\n",
    "\n",
    "*课程：python\n",
    "\n",
    "*记录人：林锦纯\n",
    "\n",
    "——————"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 上周内容"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    ">1.API文档阅读（考试）！\n",
    "\n",
    ">2.requests（考试）！\n",
    "\n",
    ">3.百度通用识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 人脸识别概念和基础"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'request_id': '1678679506,42365d69-cae9-49f0-9b5f-cfb12bf1e446', 'time_used': 305, 'faces': [{'face_token': 'e20318442575456b0e371f66d3adfe5e', 'face_rectangle': {'top': 321, 'left': 225, 'width': 289, 'height': 289}, 'attributes': {'gender': {'value': 'Male'}, 'age': {'value': 21}, 'smile': {'value': 0.013, 'threshold': 50.0}, 'headpose': {'pitch_angle': 4.938956, 'roll_angle': 1.7688848, 'yaw_angle': -7.8769727}, 'blur': {'blurness': {'value': 0.359, 'threshold': 50.0}, 'motionblur': {'value': 0.359, 'threshold': 50.0}, 'gaussianblur': {'value': 0.359, 'threshold': 50.0}}, 'emotion': {'anger': 0.001, 'disgust': 0.001, 'fear': 0.001, 'happiness': 0.005, 'neutral': 99.967, 'sadness': 0.009, 'surprise': 0.015}, 'facequality': {'value': 85.476, 'threshold': 70.1}}}], 'image_id': '8jZ4d7sDq8yTMkBddtlKxA==', 'face_num': 1}\n"
     ]
    }
   ],
   "source": [
    "# encoding:utf-8\n",
    "\n",
    "import requests\n",
    "import base64\n",
    "\n",
    "'''\n",
    "Face++人脸检测\n",
    "'''\n",
    "\n",
    "request_url = \"https://api-cn.faceplusplus.com/facepp/v3/detect\"\n",
    "# 二进制方式打开图片文件\n",
    "# 1.图片文件准备\n",
    "f = open('cxk.png', 'rb')\n",
    "img = base64.b64encode(f.read())\n",
    "\n",
    "# 2. 酬载准备\n",
    "payload={\n",
    "    'api_key':'Wkah6fZnkFvb-BNoq8fUMLkH_qZvUTcL',\n",
    "    'api_secret':'zWI1NiWGqaFWtfsjaSG8_rX7XfUmGYn5',\n",
    "    'image_base64':img,\n",
    "    'return_attributes':'gender,age,smiling,headpose,emotion,blur,facequality'\n",
    "}\n",
    "\n",
    "headers = {'content-type': 'application/x-www-form-urlencoded'}\n",
    "response = requests.post(request_url, data=payload, headers=headers)\n",
    "if response:\n",
    "    print (response.json())\n",
    "else:\n",
    "    print(response.status_code)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
